package com.nashuju.web.controller.sw;

import java.util.List;

import org.durcframework.core.DefaultGridResult;
import org.durcframework.core.GridResult;
import org.durcframework.core.MessageResult;
import org.durcframework.core.controller.CrudController;
import org.durcframework.core.expression.ExpressionQuery;

import com.nashuju.app.entity.ReqReceipt;
import com.nashuju.web.entity.sw.RUser;
import com.nashuju.web.entity.sw.RUserSch;
import com.nashuju.web.entity.sw.SReceipt;
import com.nashuju.web.entity.sw.SReceiptSch;
import com.nashuju.web.entity.sw.STaskSchedule;
import com.nashuju.web.entity.sw.STaskScheduleSch;
import com.nashuju.web.service.sw.RUserService;
import com.nashuju.web.service.sw.SReceiptService;
import com.nashuju.web.service.sw.STaskScheduleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SReceiptController extends
		CrudController<SReceipt, SReceiptService> {
	@Autowired
	RUserService rUserService;
		//新增记录
	@RequestMapping("/addSReceipt.do")
	public @ResponseBody
	MessageResult addSReceipt(SReceipt entity) {
		return this.save(entity);
	}

	//删除记录
	@RequestMapping("/delSReceipt.do")
	public @ResponseBody
	MessageResult delSReceipt(SReceipt entity) {
		return this.delete(entity);
	}
	
	//修改记录
	@RequestMapping("/updateSReceipt.do")
	public @ResponseBody
	MessageResult updateSReceipt(SReceipt entity) {
		return this.update(entity);
	}

	//条件查询分页操作
	@RequestMapping("/listSReceipt.do")
	public @ResponseBody
	GridResult listSReceipt(SReceiptSch searchEntitySch) {
		DefaultGridResult result = (DefaultGridResult)this.query(searchEntitySch);
		List<SReceipt> receipts = (List<SReceipt> )result.getRows();
		for (SReceipt reqReceipt : receipts) {
			RUserSch userSch = new RUserSch();
			userSch.setIdSch(reqReceipt.getApplyId());
			List<RUser> users = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(userSch));	
			reqReceipt.setExcutor(users.get(0));	
		}
		return result;
	}

	
	//条件查询并返回所有记录
	@RequestMapping("/listAllSReceipt.do")
    public @ResponseBody Object listAllSReceipt(SReceiptSch searchEntitySch) {
		return this.query(searchEntitySch);
       
    }

    //获取详细信息
	@RequestMapping("/getSReceiptById.do")
    public @ResponseBody SReceipt getSReceiptById(SReceipt entity) {
        return this.getService().get(entity.getId());
    }

 	

}